package com.example.sharding.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author admin
 */
@Service
@Slf4j
public class UniqueIdService {

    private static final String UNIQUE_ID_KEY = "unique_id";

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public Long generateUniqueId() {
        Long id = redisTemplate.opsForValue().increment(UNIQUE_ID_KEY);
        log.info("生成唯一ID----->{}", id);
        return id;
    }
}
